<?php
/*
Gets the html table to manage users.
*/
function get_users_manage_table($users,$controller)
{
	$CI =& get_instance();
	$table='<table class="table table-striped table-bordered table-hover" id="dataTables-example">';
	
	$headers = array('#', 
		$CI->lang->line('header_table_username'),
		$CI->lang->line('header_table_email'),
		//$CI->lang->line('header_table_phone'),
		$CI->lang->line('header_table_created_date'),
		$CI->lang->line('header_table_status'),
		$CI->lang->line('header_table_action'));
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_users_manage_table_data_rows($users,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the user.
*/
function get_users_manage_table_data_rows($users,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($users->result() as $person)
	{
		$table_data_rows.=get_user_data_row($person,$controller);
	}
	
	if($users->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='5'><div class='alert alert-info'>There is no result</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_user_data_row($person,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$is_active=($person->status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row='<tr>';
	$table_data_row.="<td>".$person->user_id."</td>";
	$table_data_row.='<td>'.character_limiter($person->username,13).'</td>';
	$table_data_row.='<td>'.mailto($person->email,character_limiter($person->email,22)).'</td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row.='<td>'.$person->created_date.'</td>';
	$table_data_row.='<td>'.$is_active.'</td>';
			
	$table_data_row.='<td><a href="'.base_url().$controller_name.'/update-user/'.$person->user_id.'" title="'.$CI->lang->line('common_edit').'"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="'.base_url().$controller_name.'/delete-user/'.$person->user_id.'" title="'.$CI->lang->line('common_delete').'" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a>| <a href="'.base_url().'user-permissions/user-modules/'.$person->user_id.'" title="Permissions"><i class="fa fa-th fa-fw fa-lg"></i></a></td>';		
	
	$table_data_row.='</tr>';
	
	return $table_data_row;
}

/*
Gets the html table to manage users group.
*/
function get_user_group_manage_table($users,$controller)
{
	$CI =& get_instance();
	$table='<table class="table table-striped table-bordered table-hover" id="dataTables-example">';
	
	$headers = array('#', 
		$CI->lang->line('header_table_username'),
		//$CI->lang->line('header_table_email'),
		//$CI->lang->line('header_table_phone'),
		$CI->lang->line('header_table_created_date'),
		$CI->lang->line('header_table_status'),
		$CI->lang->line('header_table_action'));
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_user_group_manage_table_data_rows($users,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the user.
*/
function get_user_group_manage_table_data_rows($users,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($users->result() as $person)
	{
		$table_data_rows.=get_user_group_data_row($person,$controller);
	}
	
	if($users->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='5'><div class='alert alert-info'>There is no result</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_user_group_data_row($person,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$is_active=($person->status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row='<tr>';
	$table_data_row.="<td>".$person->user_group_id."</td>";
	$table_data_row.='<td>'.character_limiter($person->name,13).'</td>';
	//$table_data_row.='<td>'.mailto($person->email,character_limiter($person->email,22)).'</td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row.='<td>'.$person->created_date.'</td>';
	$table_data_row.='<td>'.$is_active.'</td>';
			
	$table_data_row.='<td><a href="'.base_url().str_replace('_', '-', $controller_name).'/update-user-permission/'.$person->user_group_id.'" title="'.$CI->lang->line('common_edit').'"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="'.base_url().str_replace('_', '-', $controller_name).'/delete-user-permission/'.$person->user_group_id.'" title="'.$CI->lang->line('common_delete').'" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></td>';		
	
	$table_data_row.='</tr>';
	
	return $table_data_row;
}


/*
 * Get the html table to manage customer 
 * 
 */
function get_customers_manage_table($customers,$controller)
{
	$CI =& get_instance();
	$table='<table class="table table-striped table-bordered table-hover" id="dataTables-example">';
	
	$headers = array('#',
		$CI->lang->line('header_table_company_name'), 
		$CI->lang->line('header_table_username'),
		$CI->lang->line('header_table_email'),
		$CI->lang->line('header_table_status'),
		$CI->lang->line('header_table_created_date'),
		$CI->lang->line('header_table_action'));
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_customers_manage_table_data_rows($customers,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the customer.
*/
function get_customers_manage_table_data_rows($customers,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($customers->result() as $person)
	{
		$table_data_rows.=get_customer_data_row($person,$controller);
	}
	
	if($customers->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='6'><div class='alert alert-info'>There is no result</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_customer_data_row($person,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$is_active=($person->cus_status == '1') ? 'Active' : 'Disactive';
	$table_data_row='<tr>';
	$table_data_row.="<td>".$person->customer_id."</td>";
	$table_data_row.='<td>'.character_limiter($person->cus_com_name,13).'</td>';
	$table_data_row.='<td>'.character_limiter($person->cus_name,22).'</td>';
	$table_data_row.='<td>'.mailto($person->cus_email,character_limiter($person->cus_email,22)).'</td>';
	$table_data_row.='<td>'.$is_active.'</td>';
	$table_data_row.='<td>'.$person->cus_created_date.'</td>';		
	$table_data_row.='<td><a href="'.base_url().$controller_name.'/edit_customer/'.$person->customer_id.'" title="'.$CI->lang->line('common_edit').'"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="'.base_url().$controller_name.'/delete_customer/'.$person->customer_id.'" title="'.$CI->lang->line('common_delete').'"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></td>';		
	
	$table_data_row.='</tr>';
	
	return $table_data_row;
}
 
 
 /*
 * Get the html table to manage customer 
 * 
 */
function get_categories_manage_table($categories,$controller)
{
	$CI =& get_instance();
	$table='<table class="table table-striped table-bordered table-hover" id="dataTables-example">';
	
	$headers = array('#',
		$CI->lang->line('header_table_category_name'), 
		
		$CI->lang->line('header_table_status'),
		$CI->lang->line('header_table_created_date'),
		$CI->lang->line('header_table_action'));
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_categories_manage_table_data_rows($categories,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the customer.
*/
function get_categories_manage_table_data_rows($categories,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($categories->result() as $category)
	{
		$table_data_rows.=get_category_data_row($category,$controller);
	}
	
	if($categories->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='6'><div class='alert alert-info'>There is no result</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_category_data_row($category,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$is_active=($category->pro_cat_status == '1') ? 'Active' : 'Disactive';
	$table_data_row='<tr>';
	$table_data_row.="<td>".$category->pro_cat_id."</td>";
	$table_data_row.='<td>'.character_limiter($category->pro_cat_name,13).'</td>';
	
	$table_data_row.='<td>'.$is_active.'</td>';
	$table_data_row.='<td>'.$category->pro_cat_created_date.'</td>';		
	$table_data_row.='<td><a href="'.base_url().$controller_name.'/edit_category/'.$category->pro_cat_id.'" title="'.$CI->lang->line('common_edit').'"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="'.base_url().$controller_name.'/delete_category/'.$category->pro_cat_id.'" title="'.$CI->lang->line('common_delete').'"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></td>';		
	
	$table_data_row.='</tr>';
	
	return $table_data_row;
}
 
 
 
 
/*
Gets the html table to manage suppliers.
*/
function get_supplier_manage_table($suppliers,$controller)
{
	$CI =& get_instance();
	$table='<table class="tablesorter" id="sortable_table">';
	
	$headers = array('<input type="checkbox" id="select_all" />',
	$CI->lang->line('suppliers_company_name'),
	$CI->lang->line('common_last_name'),
	$CI->lang->line('common_first_name'),
	$CI->lang->line('common_email'),
	$CI->lang->line('common_phone_number'),
	'&nbsp');
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_supplier_manage_table_data_rows($suppliers,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the supplier.
*/
function get_supplier_manage_table_data_rows($suppliers,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($suppliers->result() as $supplier)
	{
		$table_data_rows.=get_supplier_data_row($supplier,$controller);
	}
	
	if($suppliers->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='7'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('common_no_persons_to_display')."</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_supplier_data_row($supplier,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$width = $controller->get_form_width();

	$table_data_row='<tr>';
	$table_data_row.="<td width='5%'><input type='checkbox' id='person_$supplier->person_id' value='".$supplier->person_id."'/></td>";
	$table_data_row.='<td width="17%">'.character_limiter($supplier->company_name,13).'</td>';
	$table_data_row.='<td width="17%">'.character_limiter($supplier->last_name,13).'</td>';
	$table_data_row.='<td width="17%">'.character_limiter($supplier->first_name,13).'</td>';
	$table_data_row.='<td width="22%">'.mailto($supplier->email,character_limiter($supplier->email,22)).'</td>';
	$table_data_row.='<td width="17%">'.character_limiter($supplier->phone_number,13).'</td>';		
	$table_data_row.='<td width="5%">'.anchor($controller_name."/view/$supplier->person_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).'</td>';		
	$table_data_row.='</tr>';
	
	return $table_data_row;
}

/*
Gets the html table to manage items.
*/
function get_items_manage_table($items,$controller)
{
	$CI =& get_instance();
	$table='<table class="tablesorter" id="sortable_table">';
	
	$headers = array('<input type="checkbox" id="select_all" />', 
	$CI->lang->line('items_item_number'),
	$CI->lang->line('items_name'),
	$CI->lang->line('items_category'),
	$CI->lang->line('items_cost_price'),
	$CI->lang->line('items_unit_price'),
	$CI->lang->line('items_tax_percents'),
	$CI->lang->line('items_quantity'),
	'&nbsp;',
	$CI->lang->line('items_inventory')
	);
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_items_manage_table_data_rows($items,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the items.
*/
function get_items_manage_table_data_rows($items,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($items->result() as $item)
	{
		$table_data_rows.=get_item_data_row($item,$controller);
	}
	
	if($items->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('items_no_items_to_display')."</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_item_data_row($item,$controller)
{
	$CI =& get_instance();
	$item_tax_info=$CI->Item_taxes->get_info($item->item_id);
	$tax_percents = '';
	foreach($item_tax_info as $tax_info)
	{
		$tax_percents.=$tax_info['percent']. '%, ';
	}
	$tax_percents=substr($tax_percents, 0, -2);
	$controller_name=strtolower(get_class($CI));
	$width = $controller->get_form_width();

	$table_data_row='<tr>';
	$table_data_row.="<td width='3%'><input type='checkbox' id='item_$item->item_id' value='".$item->item_id."'/></td>";
	$table_data_row.='<td width="15%">'.$item->item_number.'</td>';
	$table_data_row.='<td width="20%">'.$item->name.'</td>';
	$table_data_row.='<td width="14%">'.$item->category.'</td>';
	$table_data_row.='<td width="14%">'.to_currency($item->cost_price).'</td>';
	$table_data_row.='<td width="14%">'.to_currency($item->unit_price).'</td>';
	$table_data_row.='<td width="14%">'.$tax_percents.'</td>';	
	$table_data_row.='<td width="14%">'.$item->quantity.'</td>';
	$table_data_row.='<td width="5%">'.anchor($controller_name."/view/$item->item_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).'</td>';		
	
	//Ramel Inventory Tracking
	$table_data_row.='<td width="10%">'.anchor($controller_name."/inventory/$item->item_id/width:$width", $CI->lang->line('common_inv'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_count')))./*'</td>';//inventory count	
	$table_data_row.='<td width="5%">'*/'&nbsp;&nbsp;&nbsp;&nbsp;'.anchor($controller_name."/count_details/$item->item_id/width:$width", $CI->lang->line('common_det'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_details_count'))).'</td>';//inventory details	
	
	$table_data_row.='</tr>';
	return $table_data_row;
}

/*
Gets the html table to manage giftcards.
*/
function get_giftcards_manage_table( $giftcards, $controller )
{
	$CI =& get_instance();
	
	$table='<table class="tablesorter" id="sortable_table">';
	
	$headers = array('<input type="checkbox" id="select_all" />', 
	$CI->lang->line('common_last_name'),
	$CI->lang->line('common_first_name'),
	$CI->lang->line('giftcards_giftcard_number'),
	$CI->lang->line('giftcards_card_value'),
	'&nbsp', 
	);
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_giftcards_manage_table_data_rows( $giftcards, $controller );
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the giftcard.
*/
function get_giftcards_manage_table_data_rows( $giftcards, $controller )
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($giftcards->result() as $giftcard)
	{
		$table_data_rows.=get_giftcard_data_row( $giftcard, $controller );
	}
	
	if($giftcards->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('giftcards_no_giftcards_to_display')."</div></tr></tr>";
	}
	
	return $table_data_rows;
}

/** GARRISON MODIFIED 4/25/2013 **/
function get_giftcard_data_row($giftcard,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$width = $controller->get_form_width();

	$table_data_row='<tr>';
	$table_data_row.="<td width='3%'><input type='checkbox' id='giftcard_$giftcard->giftcard_id' value='".$giftcard->giftcard_id."'/></td>";
	$table_data_row.='<td width="15%">'.$giftcard->last_name.'</td>';
	$table_data_row.='<td width="15%">'.$giftcard->first_name.'</td>';
	$table_data_row.='<td width="15%">'.$giftcard->giftcard_number.'</td>';
	$table_data_row.='<td width="20%">'.to_currency($giftcard->value).'</td>';
	$table_data_row.='<td width="5%">'.anchor($controller_name."/view/$giftcard->giftcard_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).'</td>';		
	
	$table_data_row.='</tr>';
	return $table_data_row;
}
/** END GARRISON MODIFIED **/

/*
Gets the html table to manage item kits.
*/
function get_item_kits_manage_table( $item_kits, $controller )
{
	$CI =& get_instance();
	
	$table='<table class="tablesorter" id="sortable_table">';
	
	$headers = array('<input type="checkbox" id="select_all" />', 
	$CI->lang->line('item_kits_name'),
	$CI->lang->line('item_kits_description'),
	'&nbsp', 
	);
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_item_kits_manage_table_data_rows( $item_kits, $controller );
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the item kits.
*/
function get_item_kits_manage_table_data_rows( $item_kits, $controller )
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($item_kits->result() as $item_kit)
	{
		$table_data_rows.=get_item_kit_data_row( $item_kit, $controller );
	}
	
	if($item_kits->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('item_kits_no_item_kits_to_display')."</div></tr></tr>";
	}
	
	return $table_data_rows;
}

function get_item_kit_data_row($item_kit,$controller)
{
	$CI =& get_instance();
	$controller_name=strtolower(get_class($CI));
	$width = $controller->get_form_width();

	$table_data_row='<tr>';
	$table_data_row.="<td width='3%'><input type='checkbox' id='item_kit_$item_kit->item_kit_id' value='".$item_kit->item_kit_id."'/></td>";
	$table_data_row.='<td width="15%">'.$item_kit->name.'</td>';
	$table_data_row.='<td width="20%">'.character_limiter($item_kit->description, 25).'</td>';
	$table_data_row.='<td width="5%">'.anchor($controller_name."/view/$item_kit->item_kit_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).'</td>';		
	
	$table_data_row.='</tr>';
	return $table_data_row;
}

?>